mui.previewImage();

$("#main").on("click",".evaluate-title-txt-btn",function(){
	$(this).addClass("thisOn").siblings("span").removeClass("thisOn")
});
var id=getUrlParam('id');
var page=1;
getEvaluateDefaultData(page)
getEvaluateData(page)

function getEvaluateData(page) {

    $.ajax({
        type:"get",
        url:Url+"EvaluateInfo/"+id+'/page/'+page,
        async:false,
        timeout : 20000,
        beforeSend: function (xhr) {
            showDiv()
        },
        success: function(data) {
            hiddenDiv()
            if(data.count==0){
                $(".discount-main-no").css("display","block")
            }
            /*if(data.count==data.evaluate.length){
                taostr("没有更多了",2000)
            }*/
           var counts=parseInt(data.count)+parseInt(storage.getItem('counts'));
           // console.log(data);
            $(".all_evaluate").text(counts)
            $(".good_evaluate").text(parseInt(data.gods)+counts-2)
            $(".img_evaluate").text(parseInt(data.is_img)+counts-30)
            var str = '';
            for (var i = 0; i < data.evaluate.length; i++) {
                var str1 = '';
                var str2 = '';
                var str3='';
                var imgStarContent='';
                if(data.evaluate[i].evaluate_states==1){
                    for(var j=0;j<5;j++){
                        imgStarContent += '<img src="/static/index/img/starselected.png"/>';
                    }
                }else if(data.evaluate[i].evaluate_states==2){
                    for(var j=0;j<4;j++){
                        imgStarContent += '<img src="/static/index/img/starselected.png"/>';
                    }
                }else if(data.evaluate[i].evaluate_states==3){
                    for(var j=0;j<3;j++){
                        imgStarContent += '<img src="/static/index/img/starselected.png"/>';
                    }
                }
                if(data.evaluate[i].user.touimg==null){
                    str3='<img src="/static/index/img/dian.png"/>匿名'
                }else{
                    str3='<img src="'+data.evaluate[i].user.touimg+'"/>'+data.evaluate[i].user.nickname
                }
                for (var k in data.evaluate[i].speci_snap) {
                    str1 += '<span >' + k + ':' + data.evaluate[i].speci_snap[k] + '</span>'
                }
                for (var g = 0; g < data.evaluate[i].img_data.length; g++) {
                    str2 += '<img src="' + data.evaluate[i].img_data[g].eimg_url +'" data-preview-src="" data-preview-group="1"/>'
                }
                str += '<div class="evaluate-main-t">' +
                    '<div class="evaluate-main-t-title">' +
                    str3+
                    '</div>' +
                    '<div class="evaluate-main-t-time">'+data.evaluate[i].createtime+imgStarContent+'</div>' +
                    '<div class="evaluate-main-t-main">' +
                    '<span>' + data.evaluate[i].evaluate + '</span>' + str2
                    +
                    '</div>' +
                    '<div class="evaluate-main-t-name">'+data.evaluate[i].products_name + str1+ '</div></div>'
            }
            $(".evaluate-main_1").append(str)
        },
        error: function (request, status, err) {
            failure(status)
        }
    });
}

function getEvaluateDefaultData(page) {
    $.ajax({
        type:"get",
        url:Url+"Evaluates/"+id+'/page/'+page,
        async:false,
        timeout : 20000,
        beforeSend: function (xhr) {
            showDiv()
        },
        success: function(data) {
            hiddenDiv()
            if(data.count==data.evaluate.length){
                taostr("没有更多了",2000)
            }
            storage.setItem('counts',data.count);
            console.log(data);
            var str = '';
            for (var i = 0; i < data.evaluate.length; i++) {
                var str2 = '';
                var imgStarContent='';
                if(data.evaluate[i].evaluate_states==1){
                    for(var j=0;j<5;j++){
                        imgStarContent += '<img src="/static/index/img/starselected.png"/>';
                    }
                }else if(data.evaluate[i].evaluate_states==2){
                    for(var j=0;j<4;j++){
                        imgStarContent += '<img src="/static/index/img/starselected.png"/>';
                    }
                }else if(data.evaluate[i].evaluate_states==3){
                    for(var j=0;j<3;j++){
                        imgStarContent += '<img src="/static/index/img/starselected.png"/>';
                    }
                }
                if ( data.evaluate[i].evaluate_img!=0) {
                    str2 += '<img src="/static/index/img_ev/' + data.evaluate[i].type_id + '/' + data.evaluate[i].evaluate_img + '.jpg" data-preview-src="" data-preview-group="1"/>'
                }
                str += '<div class="evaluate-main-t">' +
                    '<div class="evaluate-main-t-title">' +
                    '<img src="/static/index/img_ev/touimg/'+data.evaluate[i].user_img+'.jpg"/>'+data.evaluate[i].user_name+
                    '</div>' +
                    '<div class="evaluate-main-t-time">'+data.evaluate[i].createtime+imgStarContent+'</div>' +
                    '<div class="evaluate-main-t-main">' +
                    '<span>' + data.evaluate[i].evaluate + '</span>' + str2
                    +
                    '</div>' +
                    '<div class="evaluate-main-t-name">'+data.evaluate[i].product_name + '</div></div>'
            }
            $(".evaluate-main").append(str)
        },
        error: function (request, status, err) {
            failure(status)
        }
    });
}
slideDown("#main", 61, function (e) {
    var that = this;
    getEvaluateData(page)
    getEvaluateDefaultData(page)
    that.back.call();

});
slideUp("#main", 61, function (e) {

    var that = this;
    page++;
    getEvaluateData(page)
    getEvaluateDefaultData(page)
    that.backup.call();
});
